Skip to content

fix(mac): allow ad-hoc identities for codesigning#9007

Merged
mmaietta merged 3 commits intoelectron-userland:masterfrom
kthchew:fix/macos-damaged
Apr 10, 2025
Merged

fix(mac): allow ad-hoc identities for codesigning#9007
mmaietta merged 3 commits intoelectron-userland:masterfrom
kthchew:fix/macos-damaged

Conversation

@kthchew
Copy link
Copy Markdown
Contributor

@kthchew kthchew commented Apr 3, 2025

Fixes #5850

If no signing identity is present while an app is built and it is downloaded via a web browser, macOS on ARM shows "app is damaged" errors that are hard to bypass for the average user (see #5850 and some other duplicates). This seems to be because the default signature applied by the linker to the executables isn't valid due to something the build system is doing [1]. It is thus an error to not manually codesign the resulting app, even if no stable signing identity is available (in which case it must be an ad-hoc signature).

The damaged warning is not the same as the unverified warning. Not paying for a developer account does not mean your app must show "this app is damaged" warnings to users, but it will show an unverified warning. The damaged warning cannot be bypassed through the GUI (such as in System Settings) and requires running commands to remove the quarantine attribute (as of the current macOS version). An unverified warning, on the other hand, has supported GUI methods of bypassing the warning and running the app. A proper (free) ad-hoc signature means that the damaged warning will not show up, but the unverified warning will.

Since there are no problems for those with "proper" signing certificates, it follows that the existing signing system does make a valid signature, and if it can be repurposed to accept empty identities (for ad-hoc signatures), this will resolve the issue. This PR does two main things:

  • Add an option to use ad-hoc signatures by passing - as the identity. This is the same convention that the codesign command uses.
  • Use ad-hoc signatures as a fallback by default when building ARM or universal builds if no valid identity is present. This can be overridden by setting the identity to null.

I tested these changes with FreeTube, which previously showed "'FreeTube' is damaged" warnings.
Before these changes, the warning looks like the below and can't be bypassed in System Settings.
image

With these changes, the new warning looks like
Screenshot 2025-04-02 at 4 57 11 PM
And System Settings shows an option to bypass the warning like it does on Intel.
Screenshot 2025-04-02 at 4 57 22 PM


[1] For additional details if you're curious, see the macOS 11.0.1 release notes. Specifically (emphasis mine):

To reduce the impact on existing development workflows, starting with Xcode 12 beta 4, the toolchain will now automatically sign your executables whenever you build from Xcode, or use command-line utilities such as clang(1) or ld(1). Since this signing mechanism generates signatures directly at link time, and doesn’t cover any resource other than the executable, it is expected to be faster than a traditional codesign(1) invocation. If you use a custom workflow involving tools that modify a binary after linking (e.g. strip or install_name_tool) you might need to manually call codesign(1) as an additional build phase to properly ad-hoc sign your binary.

Use such identities by default on macOS arm64 rather than doing nothing to prevent "(App) is
damaged" warnings.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: ff7ee6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/app-builder-lib/src/macPackager.ts
@mmaietta
Copy link
Copy Markdown
Collaborator

Is there a minimum supported version of codesign that supports the - Identity? Wondering if this change needs to be gated for specific MacOS versions.

@kthchew
Copy link
Copy Markdown
Contributor Author

kthchew commented Apr 10, 2025

Is there a minimum supported version of codesign that supports the - Identity? Wondering if this change needs to be gated for specific MacOS versions.

I think this has been supported since the existence of the codesign command, though I could be wrong. I’m not aware of a source that confirms this. The closest thing I could find is a reference to adhoc signing at https://developer.apple.com/documentation/security/seccodesignatureflags/adhoc that says macOS 10.0+, though that references the existence of that property rather than the - option directly.

In either case, the default use of this affects only ARM/universal builds, which are only relevant to macOS 11+. I can say with certainty that this option existed already at that point.

@kthchew
Copy link
Copy Markdown
Contributor Author

kthchew commented Apr 10, 2025

I found confirmation that --sign - has existed as an option since at least 2012, and perhaps longer (all commits on this repo were on the same date). https://github.com/Apple-FOSS-Mirror/security_systemkeychain/blame/68cbc1193007950c8c49aa63423c2e0bad4410a0/src/cs_utils.cpp#L195-L197

@beyondkmp
Copy link
Copy Markdown
Contributor

Will cause an error


dyld[3352]: Library not loaded: @rpath/Electron Framework.framework/Electron Framework
  Referenced from: <4C4C44F1-5555-3144-A109-371CAA64827A> /Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/MacOS/Cherry Studio
  Reason: tried: '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (code signature in <4C4C4421-5555-3144-A1F6-E07CD7537C3E> '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (code signature in <4C4C4421-5555-3144-A1F6-E07CD7537C3E> '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs)

@kthchew
Copy link
Copy Markdown
Contributor Author

kthchew commented Jun 28, 2025

Will cause an error


dyld[3352]: Library not loaded: @rpath/Electron Framework.framework/Electron Framework
  Referenced from: <4C4C44F1-5555-3144-A109-371CAA64827A> /Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/MacOS/Cherry Studio
  Reason: tried: '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (code signature in <4C4C4421-5555-3144-A1F6-E07CD7537C3E> '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (code signature in <4C4C4421-5555-3144-A1F6-E07CD7537C3E> '/Users/payne/Code/cherry-studio/dist/mac-arm64/Cherry Studio.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs)

Use the fix described at #5850 (comment) if you have manually set entitlements and didn’t include the one described there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Universal build fails on non-ARM64 hardware, and M1 target DMG is 'damaged'

3 participants